﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Logic.BaseContent;
using Job.Entity;

namespace Job.Web
{
    public partial class Item : BasePage
    {
        int subjectId = myR["subjectid"].IntValue;
        
        int contentId = myR["contentid"].IntValue;

        int categoryId = myR["categoryid"].IntValue;

        string jobNo = myR["jobno"].StringValue;

        int intCategoryId = 0, intSubjectId = 0, intContentId = 0;

        private void AdjustParameter()
        {
            //根据content_id来查询subject_id以及category_id
            if (contentId > 0 && subjectId <= 0)
            {
                BaseContentLogic logic = new BaseContentLogic();
                JobBaseContent info = logic.GetContentByContentId(contentId);
                if (null != info)
                {
                    intContentId = info.ContentId;
                    intSubjectId = info.SubjectId.Value;
                    BaseInfo subject = WebCommon.GetSubjectInfo(intSubjectId);
                    intCategoryId = subject.CatagoryId;
                }
            }
            else if (subjectId > 0 && categoryId <= 0)  //根据subject_id来得到category_id
            {
                intSubjectId = subjectId;
                BaseInfo subject = WebCommon.GetSubjectInfo(intSubjectId);
                intCategoryId = subject.CatagoryId;
            }
            else
            {
                intCategoryId = categoryId;
                intSubjectId = subjectId;
                intContentId = contentId;
            }
        }



        protected void Page_Load(object sender, EventArgs e)
        {
            AdjustParameter();
            LoadNavControl();
            LoadMainControl();
        }

        private void LoadNavControl()
        {
            string ctrlPath = "~/userControls/Public/SubjectNavgate.ascx";
            if (intContentId > 0)
            {
                BaseInfo info = WebCommon.GetSubjectInfo(intSubjectId);
                if (info.IsList)
                    ctrlPath = "~/userControls/Public/ContentDetailLeft.ascx";  //如果Subject为List并且指定了某一条记录时
                else
                    ctrlPath = "~/userControls/Public/SubjectNavgate.ascx";    
            }
            else if(intSubjectId > 0 )
            {                                
                //如果是二级栏目下的信息或list页面就加载导航的二级栏目，
                ctrlPath = "~/userControls/Public/SubjectNavgate.ascx";                
            }
            this.LoadCtrl(ctrlPath, "phNav");
        }

        private void LoadMainControl()
        {
            string ctrlPath = "";
            if (intSubjectId == (int)Constants.SubjectType.HunterPositionList)
            {
                if (jobNo == null || jobNo.Trim().Equals(""))
                {
                    ctrlPath = "~/userControls/Hunter/HunterJobList.ascx";
                    string newsPath = "~/userControls/Public/BottomNews.ascx";
                    this.LoadCtrl(newsPath, "phBottomNews");
                }
                else
                {
                    ctrlPath = "~/userControls/Hunter/HunterJobItem.ascx";
                    this.phBottomNews.Visible = false;
                }
            }
            else
            {
                ctrlPath = "~/userControls/Public/ContentDetail.ascx";
                if (intContentId > 0)
                {
                    ctrlPath = "~/userControls/Public/ContentDetail.ascx";
                }
                else if (intSubjectId > 0)
                {
                    bool isList = WebCommon.GetSubjectInfo(intSubjectId.ToString()).IsList;
                    if (isList)
                    {
                        ctrlPath = "~/userControls/Public/SubjectList.ascx";
                        string newsPath = "~/userControls/Public/BottomNews.ascx";
                        this.LoadCtrl(newsPath, "phBottomNews");
                    }
                    else
                    {
                        ctrlPath = "~/userControls/Public/ContentDetail.ascx";
                        this.phBottomNews.Visible = false;
                    }
                }
            }

            if (ctrlPath != "")
                this.LoadCtrl(ctrlPath, "phMain");
        }
    }
}
